import Ashily from "./Ashily.js"
import Instance from "./Instance.js"
import keyprompt from "./KeyPrompt.js"
import Math from "./Math.js"
import Asynchronous from "./Asynchronous.js"
import CropsEffects from "./CropsEffects.js"
import Cropsgrowup from "./crops_grow_up.js";

/**
 * 农作物
 */

const Crops = {

    update: function () {


        Cropsgrowup.CropsGrow()

        this.CalculatedDistance()
        this.DisplayInteractivePrompts()
    },

    onLayoutStart() {

        Crops.CurrentInteractiveCrop = null


    },


    /**
    显示互动
     */

    async DisplayInteractivePrompts() {
        let InteractionDistance = 50

        for (let crops of rt.objects.f_Crops.instances()) {
            let distance = crops.instVars.DistanceFromPlayer

            if (distance < InteractionDistance) {

                //  显示按键提示

                if (crops.instVars.GrowState != "big") {
                    keyprompt.showKeyPrompt(crops, crops.x, crops.y, "E键", "摧毁")
                }

                if (crops.instVars.GrowState == "big") {
                    keyprompt.showKeyPrompt(crops, crops.x, crops.y, "E键", "采摘")
                }


                Crops.CurrentInteractiveCrop = crops

                await Asynchronous.waitTime(1000)
                keyprompt.RebackKeyPrompt()
                Crops.CurrentInteractiveCrop = null

            }
        }

    },


    /**
     *  计算与玩家的距离
     */
    CalculatedDistance() {
        for (let crops of rt.objects.f_Crops.instances()) {

            crops.instVars.DistanceFromPlayer = Math.GetDistance(crops.x, crops.y, Ashily.ashilyInstance.x, Ashily.ashilyInstance.y)

        }
    },





}


export default Crops